using MediatR;
using MeetingManagement.Domain.Entities;
using MeetingManagement.Domain.Repositories;

namespace MeetingManagement.Application.Commands.MeetingRooms.CreateMettingRoom
{
    public class CreateMeetingRoomCommandHandler : IRequestHandler<CreateMeetingRoomCommand, Guid>
    {
        private readonly IRepository<MeetingRoom> _meetingRoomRepository;
        public CreateMeetingRoomCommandHandler(IRepository<MeetingRoom> repository)
        {
            _meetingRoomRepository = repository;
        }

        public async Task<Guid> Handle(CreateMeetingRoomCommand request, CancellationToken cancellationToken)
        {
            var room = MeetingRoom.Create(
                name: request.Name,
                location: request.Location,
                capacity: request.Capacity,
                hasProjector: request.HasProjector,
                hasWhiteboard: request.HasWhiteboard,
                hasVideoConference: request.HasVideoConference,
                description: request.Description
            );

            await _meetingRoomRepository.CreateAsync(room);
            return room.Id;
        }
    }
}
